﻿@model NeverSoldReportModel
@using Telerik.Web.Mvc.UI
@{
    var gridPageSize = EngineContext.Current.Resolve<SmartStore.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
    
    ViewBag.Title = T("Admin.SalesReport.NeverSold").Text;
}
@using (Html.BeginForm())
{
    <div class="section-header">
        <div class="title">
            <i class="fa fa-thumbs-down"></i>
            @T("Admin.SalesReport.NeverSold")
        </div>
        <div class="options">
        </div>
    </div>

	<div class="row mt-3 grid-filter">
		<div class="col-sm-6 col-lg-4 col-xl-3 form-group">
			@Html.SmartLabelFor(model => model.StartDate)
			@Html.EditorFor(model => model.StartDate)
		</div>
		<div class="col-sm-6 col-lg-4 col-xl-3 form-group">
			@Html.SmartLabelFor(model => model.EndDate)
			@Html.EditorFor(model => model.EndDate)
		</div>

		<div class="col-sm-6 col-lg-4 col-xl-3 form-group">
			@Html.SmartLabel(string.Empty, string.Empty)
			<button type="submit" id="btnSearch" value="btnSearch" class="btn btn-secondary btn-block">
				<span>@T("Admin.SalesReport.NeverSold.RunReport")</span>
			</button>
		</div>
	</div>

	<div>
		@(Html.Telerik().Grid<BestsellersReportLineModel>()
				.Name("neversoldreport-grid")
				.ClientEvents(events => events.OnDataBinding("onDataBinding"))
				.Columns(columns =>
				{
					columns.Bound(x => x.ProductName)
						.Template(x => @Html.LabeledProductName(x.ProductId, x.ProductName, x.ProductTypeName, x.ProductTypeLabelHint))
						.ClientTemplate(@Html.LabeledProductName("ProductId", "ProductName"));
				})
				.Pageable(settings => settings.PageSize(gridPageSize).Position(GridPagerPosition.Both))
				.DataBinding(dataBinding => dataBinding.Ajax().Select("NeverSoldReportList", "Order"))
				.PreserveGridState()
				.EnableCustomBinding(true))
	 </div>

    <script type="text/javascript">

        $(document).ready(function () {

            $('#btnSearch').click(function () {
                var grid = $('#neversoldreport-grid').data('tGrid');
                grid.currentPage = 1; //new search. Set page size to 1
                grid.ajaxRequest();
                return false;
            });

        });

		function onDataBinding(e) {
			var searchModel = {
				StartDate: $('#@Html.FieldIdFor(model => model.StartDate)').val(),
				EndDate: $('#@Html.FieldIdFor(model => model.EndDate)').val()
			};
			e.data = searchModel;
		}

   </script>
}